home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 82 / tutorc.eng < prev    next >
Text File  |  1986-11-20  |  8KB  |  155 lines

  1. 0660103030566
  2. 9[....................................................]
  3.  
  4.                        üC,THELANGUAGE
  5.  
  6.      WÇelcometothisfirstlessoninüCÇlanguage.Thisseriesof
  7. articlesismeantasalearningmethodforbeginningprogrammers
  8. inüCÇ.Iwillhowevertakeforgrantedthatthereaderalreadyhas
  9. somenotionssuchasknowledgeofloops,conditionnalexpressions,
  10. etc.
  11.  
  12.      Hereisthefirstwarning.TheüCÇlanguageisnotaneasy
  13. language.Itisaflexiblelanguage,generatingfastandcompact
  14. codebutitisveryhardtodebug.Errormessages,whenthereare
  15. any(...),arenotextremelysignificantandmayreferto
  16. correctlywritteninstructions(therealerrormightinfactbe
  17. anywhere...).
  18.  
  19.      Asecondwarning.TheexistingversionsofüCÇavailableonthe
  20. üSTÇarecompiledlanguages.Thismeansthattheyarenotdirectly
  21. executablelikeüSTBasicÇorüAtariLOGOÇ.(Thoseareinterpreted
  22. languages).Youcannot,forexample,typealineofcodeandsee
  23. (orobserve)itseffectimmediately.Manystepsarenecessary
  24. beforeyouobtainareadytorunprogram.Tofindtherightsteps,
  25. toexecutetheminorder,willtakemoretimeduringthefirst
  26. triesthanwritingtheprogramitself.
  27.  
  28.      Ifthisintroductionhasn'tdiscouragedyou,youareready
  29. foryourfirstplunge.
  30.  
  31.      First,youneedaprogrameditor.Manyofthemareavailable
  32. onthemarket:üMinceÇorüMicro-EmacsÇ,orsimpler;awordprocessing
  33. programsuchasü1st-WordÇ.Withthelatter,youmustbecarefulnot
  34. toselecttheWPmode,becauseitwillinsertinthetextsome
  35. controlcharactersthatwillnotberecognizedbythecompiler.
  36.  
  37.      Typethefollowinglines:
  38.  
  39. #üinclude"osbind.h"
  40.  
  41. main()Ç
  42. {ü
  43. Cconws("ThisismyfirstCprogram");
  44. Cconin();
  45. Ç}
  46.  
  47.  
  48.      Savethistextfileunderthename"üMYFIRST.CÇ"
  49.  
  50.      Let'snowanalysethisprogramindetail.Thefirstline,
  51. #üincludeÇ"üosbind.hÇ",containsthe#character.Thissymbolsignals
  52. tothecompilerthearrivalofapre-processorcommand.Itmustbe
  53. usedonlyinthismanner(unlessitappearsinasentencebetween
  54. quotes).TheüincludeÇpre-processorcommandincludestheüosbind.hÇ
  55. fileinsidethecode.Thisfilecontainsdefinitionsforthe
  56. üCconwsÇandüCconinÇofourprogramand,inamoregeneralway,it
  57. containsthedefinitionsoftheüCPM-68KÇoperatingsystem.This
  58. typeoffilewhichcontainsdefinitions,ischaracterizedbyits
  59. ü.hÇextension.Forexample,theüvdibind.hÇandüaesbind.hÇfilesare
  60. definitionsfortheüVDIÇandüAESÇ;theyareentrypointstotheüGEMÇ.
  61. Noticethatthenameofthefilemustbebetweenquotes.
  62.  
  63.      Thesecondline,ümain()Ç,tellsthecompilerthattheprogram
  64. executionmustbeginhere.Theümain()Çfunctionmayinfactbe
  65. anywhereinsidethetext.InüCÇ,exceptionmadeofthepre-
  66. processorcommands,onlyfunctionsexist.Functionswhichcall
  67. otherfunctionswhichcallyetmorefunctions,etc...Thefirst
  68. functiontobeexecutedisalwaysümain()Çevenifitisnotthe
  69. firstonetoappearinthetext.
  70.  
  71.      Afunctionisdistinguishablebythepresenceofparenthesis
  72. whichalwaysfollowthenameofthefunction.Theseparenthesis
  73. containtheargument(s)ofthefunction.Theümain()Çfunctiontakes
  74. noargumentsso,the(compulsary)parenthesisareempty.The
  75. üCconwsÇfunctioncontainsanargument,thesentence:"üThisismy
  76. firstCprogramÇ",thisfunctionwillwritethelineoftextonthe
  77. screenatthecurrentcursorlocation,here,theupperleft
  78. corner.(üCconswÇistheabbreviationfor'üConsolewritestringÇ'.)
  79. Thequotesdelimitingthesentencearenecessaryaswellasthe
  80. semicolonendingthelineüCconsw(Ç"üThisismyfirstCprogramÇ"ü);
  81. ÇTheabsenceofthispunctuationwillreturnanerrormessage
  82. duringcompilation.
  83.  
  84.      Thesemicoloniswhatiscalled,inprogrammer'sslang,a
  85. delimiter.Itspecifiesthateverythingprecedingitalltheway
  86. backtotheprevioussemicolonorbacktothestartofthe
  87. functionproper,isafunctionthatiscompletebyitself.The
  88. semicolondelimitatesthebodyoftheprecedingfunction.
  89.  
  90.      Thefollowingfunction,üCconin();Çwaitsforsomecharacterto
  91. betypedonthekeyboardanddisplaysitonthescreen(ifitisa
  92. printableASCIIcharacter).üCconinÇistheabbreviationfor
  93. 'üConsoleInputÇ'.Thereisanotherfunctionthatdoesthesamejob,
  94. butwithoutprintingthecharacter;itsnameisüCnecin()Ç.Thisone
  95. mustbeusedduringapauseinsideaprogram,forexample.
  96.  
  97.      Onthelastlinewefindaclosingbracket'ü}Ç',whichis
  98. alwayspairedtoanopeningbracket'ü{Ç'.Theyareusedtolimit
  99. thefieldoftheümain()Çfunction,'ü{Ç'markingthestartand'ü}Ç'at
  100. theend.TheyareusedinthesamemannerintestsusingüwhileÇor
  101. üifÇ-üthenÇ-üelseÇaswewillseelater.
  102.  
  103.      Allthatisleftforustodonowisto"compile"this
  104. program.Thecompilationistheprocessbywhichthecomputer
  105. translatestheprogramtextinbinaryinstructions(i.e.machine
  106. language)andplacestheseinstructionsinafilewithaü.PRGÇ
  107. suffix.Thisfileisdirectlyexecutable,meaningthatitdoesn't
  108. needanotherprogramtorunit,(forexampletakeaüLOGOÇprogram
  109. whichneedstheüLOGO.PRGÇfiletowork).
  110.  
  111.      Thecompilationstepsneededvaryfromonecompilerto
  112. another.ForthecompilerthatcomeswiththeüAtariÇüToolkitÇ,the
  113. stepstofolloware:
  114.  
  115. üCP68KMYFIRST.CMYFIRST.I
  116. ÇüC068MYFIRST.IMYFIRST.1MYFIRST.2MYFIRST.3-F
  117. C168MYFIRST.1MYFIRST.2MYFIRST.S
  118. AS68-L-UMYFIRST.S
  119. Ç
  120. üLINK68[U]MYFIRST.68K=APSTART,MYFIRST,GEMLIB
  121. RELMODMYFIRST
  122. Ç
  123.      ThefirstfourstepsproducethefileüMYFIRST.SÇ,üÇwhichisan
  124. assemblylanguagefile(accordingtoüMotorolaÇmnemoniccodes).The
  125. twolaststepswillgeneratethedesiredfile,üMYFIRST.PRGÇ.
  126.  
  127. ü     ÇThenamesatthestartofeachofthefirstfourlinesabove
  128. correspondtothenamesoffilesonthe"üCompilerDiskÇ"andthe
  129. lasttwocorrespondtonamesoffilesonthe"üLinkerDiskÇ".You
  130. mustexecutetheseprogramsbyenteringtheparametersthatfollow
  131. thenameinthelineinthefollowingmanner:'click'onceonthe
  132. nameoftheprogram,selectüInstallApplicationÇintheüOPTION
  133. Çchoice(menubar)ü,Çandwriteintherequiredparameters.
  134.  
  135.      AsecondmethodconsistsincallingtheüCOMMAND.PRGÇprogram
  136. (itisincludedineachofthediskettesmentionned)andwritein
  137. thelinesasabove.
  138.  
  139.      Athirdmethod,theonemostoftenused,callsfortheü.BATÇ
  140. filemethod.Thesefilescontaintheequivalentofthelines
  141. above.Forexample,theüC.BATÇfilecontainsthefirstfourlines
  142. above;weexecutethisfilebycallingtheüBATCH.PRGÇandbytyping
  143. üC.MYFIRSTÇ(andnotüC.BATMYFIRST.CÇasmighthavebeenexpected).
  144. Forthetwolastlines,calltheüBATCH.PRGÇwiththeparameters
  145. üLINKCMYFIRSTÇ(thisone'snamewillvaryaccordingtoyourversion
  146. oftheüTOOLKITÇ).
  147.  
  148.      Whenyouhavefinished,yourfirstprogramwillappearunder
  149. thenameüMYFIRST.PRGÇ.Tryit...Inthenextlesson,wewill
  150. examinehowtouseloopsandconditionnalexpressions.
  151.  
  152. üAlainBirtz
  153. March1986Ç
  154.  
  155.